package demoMod.plugins.mod.sts.inspections;

import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.util.ObjectUtils;
import org.jetbrains.annotations.NotNull;

public class AddInitializeMethodQuickFix implements LocalQuickFix {
    @Override
    public @NotNull String getFamilyName() {
        return "!Fix: add initialize method";
    }

    @Override
    public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
        PsiClass aClass = ObjectUtils.tryCast(descriptor.getPsiElement(), PsiClass.class);
        if (aClass == null) {
            return;
        }

        PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);

        PsiMethod secureNewExp = factory.createMethodFromText("public static void initialize() {\n        //TODO:Add your initialize code here.\n}", null);
        aClass.add(secureNewExp);
    }
}
